package per.yd.tankWar.entity;

import java.awt.Image;
import java.awt.Rectangle;

import per.yd.tankWar.utils.ImageUtils;

public class DisplayImage {
	
	public int x;
	
	public int y;
	
	public int width;
	
	public int height;
	
	public Image image;
	
	public DisplayImage() {
		
	}
	
	public DisplayImage(int x, int y, String url) {
		this.x = x;
		this.y = y;
		this.image = ImageUtils.getImageByUrl(url);
		this.width = image.getWidth(null);
		this.height = image.getHeight(null);
	}
	
	public DisplayImage(int x, int y, int height, int width) {
		this.x = x;
		this.y = y;
		this.height = height;
		this.width = width;
	}
	
	
	public boolean hit(DisplayImage tankImage) {
		Rectangle other = tankImage.getRectangle();
		return hit(other);
	}
	
	
	public boolean hit (Rectangle r) {
		
		if(r == null ) {
			return false;
		}
		
		return r.intersects(getRectangle());
	}
	
	public Rectangle getRectangle() {
		return new Rectangle(x, y, this.width,this.height);
	}
	
	public Image getImage() {
		return image;
	}
	
	
}
